(defmodule MAIN (export ?ALL))

(deftemplate MAIN::map-object
(slot type (type STRING))
(slot id (type INTEGER))
(slot x (type INTEGER))
(slot y (type INTEGER))
(slot energy (type INTEGER))
)

(deftemplate MAIN::near-empty
(slot target-id (type INTEGER))
(slot direction (type STRING))
(slot id (type INTEGER))
(slot x (type INTEGER))
(slot y (type INTEGER))
)

(defrule MAIN::start
  (declare (salience 10000))
  =>
  (set-fact-duplication TRUE)
  (focus MAP))

(defmodule MAP (import MAIN ?ALL) (export deffunction get-action))

(deftemplate MAP::action
  (slot name (type STRING))
  (slot id (type INTEGER))
  (slot type (type STRING))
  (slot direction (type STRING))
  (slot target-id (type INTEGER) (default 0))
)

(defrule MAP::replenish-first
	?m <- (action (name "move") (direction ?dir) (type "human") (id ?id))
	(action (name "replenish") (type "human") (id ?id))
	=>
	(retract ?m)
)

(defrule MAP::attack-first
	?m <- (action (name "move") (direction ?dir) (type "human") (id ?id))
	(action (name "attack") (type "zombie") (id ?id))
	=>
	(retract ?m)
)

(deffunction MAP::get-action ()
(bind ?actions (find-all-facts ((?a action)) TRUE))
 )
  